#include <QtCore/QString>
#include <QtTest/QtTest>
#include <QList>
#include "PersistentListTests.h"
#include "WrapFactory.h"

namespace clojure_lang {



PersistentListTests::PersistentListTests()
{

}

void PersistentListTests::OneArgCtorConstructsListOfOneElement()
{
    PersistentList *lst = NewRef(PersistentList, (wrap("abc")));

    //PersistentList *lst = PersistentList_(new PersistentList(new CjTypeWrapper(QString("abc"))));


    QVERIFY2(lst->first()->equals(wrap("abc")), "First Matches");
    QVERIFY2(lst->next() == NULL, "Next is Null" );
    QVERIFY2(lst->count() == 1, "Count Matches");
}

void PersistentListTests::ListCtorConstructsListOfSeveralElements()
{

    /*QList<CjObject *> qlst = QList<CjObject_>();
    qlst.append(wrap(1));
    qlst.append(wrap("abc"));
    qlst.append(wrap(2));
    qlst.append(wrap("def"));*/
    IPersistentList *lst = PersistentList::createEx(wrap(1), wrap("abc"), wrap(2), wrap("def"))->dynamicCast<IPersistentList>();
    //PersistentList *lst = NewRef(PersistentList, (NewRef(CjTypeWrapper, QString("abc"))));
    //IPersistentList *lst = PersistentList::create(&qlst);
    ISeq *s = lst->seq();
    QVERIFY2(s->count() == 4, "Count = 4");
    QVERIFY2(s->first()->equals(wrap(1)), "First Matches");
    QVERIFY2(s->next()->first()->equals(wrap("abc")), "Seccond Matches");
    QVERIFY2(s->next()->next()->first()->equals(wrap(2)), "Third Matches");
    QVERIFY2(s->next()->next()->next()->first()->equals(wrap("def")), "Fourth Matches");
    QVERIFY2(s->next()->next()->next()->next() == NULL, "Fifth is NULL");

}

void PersistentListTests::PeekYieldsFirstElementAndListUnchanged()
{
    IPersistentList *lst = PersistentList::createEx(wrap(1), wrap("abc"), wrap(2), wrap("def"))->dynamicCast<IPersistentList>();


    QVERIFY2(lst->peek()->equals(wrap(1)), "Peek Matches");

    QVERIFY2(lst->count() == 3, "Count = 3");

}

void PersistentListTests::PopLosesfirstElement()
{
    IPersistentList *lst = PersistentList::createEx(wrap("abc"), wrap(2), wrap("def"))->dynamicCast<IPersistentList>();

    PersistentList *p2 = dynamic_cast<PersistentList *>(lst->pop());

    QVERIFY2(p2->count() == 2, "Count == 2");

    QVERIFY2(p2->peek()->equals(wrap(2)), "Peek Matches");

}

void PersistentListTests::EmptyHasNoElements()
{
    PersistentList *p = PersistentList::createEx(wrap("abc"))->dynamicCast<PersistentList>();
    IPersistentCollection *c = p->empty();//p->empty();

    //QVERIFY2(c->count() == 0, "Empty Length = 0");

}

void PersistentListTests::PopOnSingletonYieldsEmptyList()
{
    /*PersistentList *lst = NewRef(PersistentList, (NewRef(CjTypeWrapper, QString("abc"))));
    IPersistentStack * p = lst->pop();
    QVERIFY2(p->count() == 0, "Size = 0");*/
}

PersistentList::Ctor PersistentList::createEx;


}

